#include "my_queue.h"

int main() {
    pQueue qMan = make_queue();
    pQueue qMan_ =make_queue();
    pQueue qWoman =make_queue();
    pQueue qWoman_=make_queue();
    int man,woman,turn;
    char* tmp_name = calloc(100,sizeof(char));
    printf("男队：\n");
    printf("输入跳舞者人数：");scanf("%d",&man);
    printf("输入跳舞者的姓名：");
    for(int i=0;i<man;i++) {
        scanf("%s", tmp_name);
        pItem item = calloc(1,sizeof(Item));
        item->name = calloc(strlen(tmp_name) + 1,sizeof(char));
        strcpy(item->name,tmp_name);
        enqueue(qMan,item);
    }
//    print_queue(qMan);

    printf("女队：\n");
    printf("输入跳舞者人数：");scanf("%d",&woman);
    printf("输入跳舞者的姓名：");
    for(int i=0;i<woman;i++) {
        scanf("%s", tmp_name);
        pItem item = calloc(1,sizeof(Item));
        item->name = calloc(strlen(tmp_name) + 1,sizeof(char));
        strcpy(item->name,tmp_name);
        enqueue(qWoman,item);
    }
    free(tmp_name);
//    print_queue(qWoman);

    printf("输入舞会的轮数：");scanf("%d",&turn);

    while(turn--){
        int count = 0;
        while(front(qMan)&&front(qWoman)){
            printf("配对的舞者：%s %s\n",front(qMan)->name,front(qWoman)->name);
            enqueue(qMan_,dequeue_k(qMan));
            enqueue(qWoman_,dequeue_k(qWoman));
            ++count;
        }
        if(!front(qMan)){
            printf("第一个出场的未配对舞者的姓名：%s\n",front(qWoman)->name);
        }
        if(!front(qWoman)){
            printf("第一个出场的未配对舞者的姓名：%s\n",front(qMan)->name);
        }
        while(count--){
            enqueue(qMan,dequeue_k(qMan_));
            enqueue(qWoman,dequeue_k(qWoman_));
        }
    }

    destroy_queue(qMan);
    destroy_queue(qWoman);
    destroy_queue(qMan_);
    destroy_queue(qWoman_);
    return 0;
}
